import Request from '@/utils/request'
import Cookies from '@/utils/auth'

const state = () => ({
	editIncentivePolicy:true,
	showType:1, // 1显示广告内容表单输入界面，2显示非表单界面，但可以切换到编辑界面，3只显示非表单界面，不可切换到编辑（不可编辑）
	deliveryCon:{
		adDays:31,//	投放时长（天）		false	
		adInfo:'',//	广告内容		false	
		adPlaceId:'',//	关联广告位id		false	
		adUrl:'',//	广告位链接
		allTotalPrice:'', // 投放奖励总和
		dayTotalPrice:'',// 每日奖励上限
		type:'simplePic', 
	},  //广告投放的内容
	ads_tab_index:1, // 1投放请求,2待投放未设置内容,3投放生效,4停止投放,5广告内容设置编辑，6奖励设置，7待投放已设置内容
	cur_adPlaceJobId:'' // 当前选择的adPlaceJobId
})
const getters = {
	
}
const mutations = {
	set_editAdRelease: (state, data) => {
		state.editAdRelease = data
	},
	set_editIncentivePolicy: (state, data) => {
		state.editIncentivePolicy = data
	},
	set_deliveryCon: (state, obj) => {
		Object.assign(state.deliveryCon,obj)  // 把obj合并到deliveryCon中，如有相同属性的则替换值
	},
	clear_deliveryCon: (state) => {
		state.deliveryCon = {
			adDays:31,
			type:'simplePic'
		}
	},
	set_ads_tab_index: (state, data) => {
		state.ads_tab_index = data
	},
	set_showType: (state, data) => {
		state.showType = data
	},
	set_adAnalys: (state, obj) => {
		Object.assign(state.adAnalys,obj)
	},
	set_cur_adPlaceJobId: (state, data) => {
		state.cur_adPlaceJobId = data
	},
}
const actions = {
	async get_adspace_list({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/listPageAdPlacer',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_adspace_detail({commit}, adPlaceId) {  
		return new Promise((resolve,reject)=>{
			Request.get(`/api/adPlace/detailAdPlacer/${adPlaceId}`,)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_prop_list({commit}, params) { // 道具列表
		return new Promise((resolve,reject)=>{
			let fromData = new FormData()
			for (const key in params) {
				fromData.append(key, params[key])
			}
			Request.post('/api/arprop/arprop-list-my-all',fromData)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_arproptemplate_userprop_list({commit}, params) { // 可兑换道具列表
		return new Promise((resolve,reject)=>{
			Request.post('/api/arprop-template/arproptemplate-user-list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_prop_detail({commit}, arPropId) { // 道具详情
		return new Promise((resolve,reject)=>{
			const formData = new FormData()
			formData.append('arPropId',arPropId)
			Request.post('/api/arprop/arprop-detail',formData)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_arproptemplate_detail({commit}, arPropId) { // 可兑换道具详情
		return new Promise((resolve,reject)=>{
			const formData = new FormData()
			formData.append('propTemplateId',arPropId)
			Request.post('/api/arprop-template/arproptemplate-detail',formData)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_my_list({commit}, params) { // 我持有的：AR地标，AR广告，AR道具
		return new Promise((resolve,reject)=>{
			Request.post('/api/arLandmark/myList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_status_total({commit}, params) { // 获取广告各状态的数量
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getAdPlaceStatusAmount',params,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	// async ad_place_request({commit}, params) { // 上线广告位
	// 	return new Promise((resolve,reject)=>{
	// 		Request.post('/api/adPlaceJob/applyOnlineAdPlaceJob',params)
	// 		.then(res=>{
	// 			resolve(res.data) 
	// 		})
	// 	})
	// },

	async add_ad_place({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/add',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_ads_release_List({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/listPageAdPlaceJobReleaseList',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_ads_request_List({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/listPageApplyAdPlaceJob',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_ads_apply_detail({commit}, adPlaceJobId) {
		return new Promise((resolve,reject)=>{
			//Request.post(`/api/adPlaceJob/applyDetailAdPlacerJob/${adPlaceJobId}`)
			Request.post(`/api/adPlaceJob/detail/${adPlaceJobId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	
	async tognyi_apply({commit}, adPlaceJobId) {
		return new Promise((resolve,reject)=>{
			Request.post(`/api/adPlaceJob/acceptApplyAdPlaceJob/${adPlaceJobId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async ads_online({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/applyOnlineAdPlaceJob',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async ads_stop_online({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/offLineAdPlaceJobRecord',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async ads_valid_stop_list({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJobRecord/listPageAdPlaceJobRecord',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_global_rank({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/listPageAdPlaceMerchantEffect',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_award_statistics({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceAwardRecord/getAdPlaceAwardStatistics',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_adser_je({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceAwardRecord/getAdPlaceMerchantFund',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_uvpv_chart_data({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/common/visit/getTrend',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_visit_rank({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getAdPlaceRank',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_wait_release({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/listPageAdPlaceMerchant',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async add_wait_release({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/addAdPlaceMerchant',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_ads_income_rank({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getAllAdPlaceAwardRank',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async reward_distribution_trend({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceAwardRecord/getAwardGrantTrend',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async my_release_ads_list({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceAwardRecord/listPageAdPlaceMerchantEffect',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async my_ads_release_status_number({commit}, walletAddress) {
		return new Promise((resolve,reject)=>{
			// //let urlScData = new URLSearchParams()
			// let formData = new FormData()
			// for (const key in params) {
			// 	formData.append(key, params[key])
			// }
			Request.get(`/api/adPlace/getAdPlaceMerchantMultipleAmount?walletAddress=${walletAddress}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async set_ads_cpc({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/editAdLandmarkConfigCPC',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async set_ads_award({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/editAdLandmarkConfigAward',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_rule_detail({commit}, arLandmarkId) {
		return new Promise((resolve,reject)=>{
			Request.get(`/api/adPlace/detailAdLandmarkConfig/${arLandmarkId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async update_ads_con({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/update',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async batch_launch({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlaceJob/batchApplyOnlineAdPlaceJob',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_ads_visit_rank({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getAllAdPlacePVRank',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_ads_expend_statistics({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getMyAdPlaceAwardGrantStatistics',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_global_ads_income_rank({commit}, params) {
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/listPageAdPlaceAwardRank',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_my_ads_income_rank({commit}, walletAddress) {
		return new Promise((resolve,reject)=>{
			Request.post(`/api/adPlace/myAdPlaceAwardRank?walletAddress=${walletAddress}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_ads_chain_info({commit}, adPlaceId) {
		return new Promise((resolve,reject)=>{
			Request.get(`/api/adPlace/detailAdPlacerNft/${adPlaceId}`)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async get_city_prop_list({commit}, params) { // 城市道具列表
		return new Promise((resolve,reject)=>{
			let fromData = new FormData()
			for (const key in params) {
				fromData.append(key, params[key])
			}
			Request.post('/api/arprop/arprop-list-scene',fromData,{unLoading:true})
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async add_ad_place_pv({commit}, params) {
		return new Promise((resolve,reject)=>{
			// api/adPlace/addAdPlaceVisit 原来的
			Request.post('/api/adPlace/addAdPlaceVisit',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async getDepositItems({commit}, params) { //我的保证金明细
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getDepositItems',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async getTotalPriceItems({commit}, params) { //我的奖金池明细
		return new Promise((resolve,reject)=>{
			Request.post('/api/adPlace/getTotalPriceItems',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
